import { defineStore } from 'pinia'
import { requestPoemsList, requestAddPoetryToPoemsList, requestSearchPoemsListByNameAndUid, requestSearchPoemsListByNameOrUid, requestCreatePoemsList, requestDeletePoemsListById, requestPoemsListDetailByPlId, requestEditPoemsListInfo } from './manage-poemsList.api'

export default defineStore('managePoemsList', {
    state: () => {
        return {
        }
    },
    getters: {
    },
    actions: {
        // 获取全部诗单信息
        getPoemsList(data: object) {
            return new Promise((resolve, reject) => {
                requestPoemsList(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 将诗歌加入诗单
        getAddPoetryToPoemsList(data: object) {
            return new Promise((resolve, reject) => {
                requestAddPoetryToPoemsList(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据uid和诗单名称搜索诗单
        getSearchPoemsListByNameAndUid(data: object) {
            return new Promise((resolve, reject) => {
                requestSearchPoemsListByNameAndUid(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据uid或诗单名称搜索诗单（模糊查询）
        getSearchPoemsListByNameOrUid(data: object) {
            return new Promise((resolve, reject) => {
                requestSearchPoemsListByNameOrUid(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 创建诗单
        getCreatePoemsList(data: object) {
            return new Promise((resolve, reject) => {
                requestCreatePoemsList(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据id删除诗单
        getDeletePoemsListById(data: object) {
            return new Promise((resolve, reject) => {
                requestDeletePoemsListById(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 根据id获取诗单详情
        getPoemsListDetailByPlId(data: object) {
            return new Promise((resolve, reject) => {
                requestPoemsListDetailByPlId(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        },

        // 编辑诗单
        getEditPoemsListInfo(data: object) {
            return new Promise((resolve, reject) => {
                requestEditPoemsListInfo(data).then(response => {
                    const res: any = response.data
                    if (res.code === 200) {
                        resolve(res.data)
                    }
                })
            })
        }
    }
})
